package com.aura.bookshop.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

// @Configuration
// public class MyWebConfig extends WebMvcConfigurationSupport {
//     @Override
//     protected void addViewControllers(ViewControllerRegistry registry) {
// //        super.addViewControllers(registry);
//         registry.addViewController("/index.html").setViewName("index");
//         registry.addViewController("/").setViewName("index");
//     }
//
//     @Override
//     protected void addInterceptors(InterceptorRegistry registry) {
// //        super.addInterceptors(registry);
//         registry.addInterceptor(new MyWebIntercept())
//                 .addPathPatterns("/**")
//                 .excludePathPatterns("/","/index.html","/user/login","/rest/**");
//     }
//     //静态资源配置
//     @Override
//     protected void addResourceHandlers(ResourceHandlerRegistry registry) {
//
//         registry.addResourceHandler("/js/**").addResourceLocations("classpath:/static/js/");
//     }
//
// }

@Configuration
 class MyMvcWebConfig implements WebMvcConfigurer{

        @Override
    public void addViewControllers(ViewControllerRegistry registry) {
//        super.addViewControllers(registry);
        registry.addViewController("/index.html").setViewName("index");
        registry.addViewController("/").setViewName("index");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        super.addInterceptors(registry);
        registry.addInterceptor(new MyWebIntercept())
                .addPathPatterns("/**")
                .excludePathPatterns("/","/index.html","/user/login","/rest/**");
    }
}